com.sabro.jbusiness.sys
Class SysConexao

java.lang.Object
  extended by com.sabro.jbusiness.sys.SysConexao
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.sql.Connection, java.sql.Wrapper

public class SysConexao
extends java.lang.Object
implements java.sql.Connection, java.io.Externalizable

Usada para genenciar conexões com banco de dados

Author:
Dalton Salvatti
See Also:
Serialized Form

Nested Class Summary
static class SysConexao.DriverType
           
 
Field Summary
static java.lang.String nomeGrupoUsers
           
static java.lang.String nomeUsuarioAdmins
           
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
SysConexao()
           
 
Method Summary
 boolean ativaConexao()
           
 void clearWarnings()
           
 void close()
          Este método foi alterado para se tornar inativo.
 void closeConexao()
           
 void commit()
           
 java.sql.Array createArrayOf(java.lang.String typeName, java.lang.Object[] elements)
           
 java.sql.Blob createBlob()
           
 java.sql.Clob createClob()
           
 java.sql.NClob createNClob()
           
 java.sql.SQLXML createSQLXML()
           
 java.sql.Statement createStatement()
           
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
           
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 java.sql.Struct createStruct(java.lang.String typeName, java.lang.Object[] attributes)
           
 int getAdminsId()
           
 java.lang.String getAlias()
           
 boolean getAutoCommit()
           
 java.lang.String getCatalog()
           
 java.util.Properties getClientInfo()
           
 java.lang.String getClientInfo(java.lang.String name)
           
 java.sql.Connection getConexao()
           
static java.lang.String getConexaoAtivaNome()
           
 SysConexao.DriverType getDriverType()
           
 java.lang.String getEdition()
           
static java.lang.String getGrupoGR(int id)
          Retorna o nome técnico do grupo no banco de dados no formato GR_XXXXX.
 int getHoldability()
           
static java.util.ArrayList<java.lang.String> getListaConexoes()
           
 java.lang.String getLogin()
           
 java.sql.DatabaseMetaData getMetaData()
           
 java.lang.String getNome()
           
 java.lang.String getNomeAmbiente()
           
 java.lang.String getNomeDb()
           
 java.lang.String getProductLevel()
           
 java.lang.String getProductVersion()
           
 java.lang.String getSenha()
           
 int getSpId()
           
static SysConexao getSysConexao()
           
static SysConexao getSysConexao(java.util.HashMap<java.lang.String,java.lang.String> parametros)
           
static SysConexao getSysConexao(java.lang.String nome)
           
static java.util.ArrayList<SysConexao> getSysConexaos()
           
 int getTransactionIsolation()
           
 java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap()
           
 java.lang.String getUrlServidor()
           
 int getUsersId()
           
 java.lang.String getUsuario()
           
static java.lang.String getUsuario(SysConexao sysConexao)
           
 int getUsuarioId()
           
static int getUsuarioId(SysConexao sysConexao)
           
static java.lang.String getUsuarioUS(int id)
          Retorna o nome técnico do usuário no banco de dados no formato US_XXXXX.
 java.sql.SQLWarning getWarnings()
           
 void initGrupos()
          Preenche a variável global "Grupos" com a relação de grupos do usuário corrente.
 void initGrupos(int usuarioID)
          Preenche a variável global "Grupos" com a relação de grupos do usuário informado.
 boolean isClosed()
           
 boolean isDbOwner()
           
 boolean isMemberOf(int grupoId)
          Informa se o usuário corrente faz parte do grupo informado.
 boolean isMemberOfAdmins()
           
static boolean isMemberOfAdmins(SysConexao sysConexao)
           
 boolean isMemberOfProcessAdmin()
          Verifica se o usuário que está logado no sistema e membro do grupo processadmin
static boolean isMemberOfProcessAdmin(SysConexao sysConexao)
           
 boolean isReadOnly()
           
 boolean isValid(int timeout)
           
 boolean isWrapperFor(java.lang.Class<?> arg0)
           
 java.lang.String nativeSQL(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames)
           
 void readConexao()
          Carrega a conexão de um arquivo no formato cnx
 void readExternal(java.io.ObjectInput in)
           
 boolean reativaConexao(java.lang.Object mensagem)
           
 void releaseSavepoint(java.sql.Savepoint savepoint)
           
 void rollback()
           
 void rollback(java.sql.Savepoint savepoint)
           
 void saveConexao()
          Salva a conexão em arquivo
static void saveConexao(SysConexao sysConexao)
          Salva a conexão em arquivo
 void setAutoCommit(boolean autoCommit)
           
 void setCatalog(java.lang.String catalog)
           
 void setClientInfo(java.util.Properties properties)
           
 void setClientInfo(java.lang.String name, java.lang.String value)
           
 void setConexao(java.sql.Connection conexao)
           
static java.sql.Connection setConexao(SysConexao.DriverType driverType, java.lang.String servidor, java.lang.String database, java.lang.String login, java.lang.String senha, java.lang.String programa)
          Obtém uma conexão com um banco de dados SQL Server.
 void setDriverType(SysConexao.DriverType driverType)
           
 void setHoldability(int holdability)
           
 void setLogin(java.lang.String login)
           
 void setNome(java.lang.String nome)
           
 void setNomeAmbiente(java.lang.String nomeAmbiente)
           
 void setNomeDb(java.lang.String nomeDb)
           
 void setReadOnly(boolean readOnly)
           
 java.sql.Savepoint setSavepoint()
           
 java.sql.Savepoint setSavepoint(java.lang.String name)
           
 void setSenha(java.lang.String senha)
           
static void setSysConexao(SysConexao sysConexao)
           
 void setTransactionIsolation(int level)
           
 void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)
           
 void setUrlServidor(java.lang.String urlServidor)
           
 java.lang.String toString()
           
<T> T
unwrap(java.lang.Class<T> arg0)
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nomeUsuarioAdmins

public static final java.lang.String nomeUsuarioAdmins
See Also:
Constant Field Values

nomeGrupoUsers

public static final java.lang.String nomeGrupoUsers
See Also:
Constant Field Values
Constructor Detail

SysConexao

public SysConexao()
Method Detail

getSysConexao

public static SysConexao getSysConexao()

getSysConexao

public static SysConexao getSysConexao(java.lang.String nome)

getSysConexao

public static SysConexao getSysConexao(java.util.HashMap<java.lang.String,java.lang.String> parametros)

getConexaoAtivaNome

public static java.lang.String getConexaoAtivaNome()

setSysConexao

public static void setSysConexao(SysConexao sysConexao)

reativaConexao

public boolean reativaConexao(java.lang.Object mensagem)

ativaConexao

public boolean ativaConexao()

getSysConexaos

public static java.util.ArrayList<SysConexao> getSysConexaos()

setConexao

public static java.sql.Connection setConexao(SysConexao.DriverType driverType,
                                             java.lang.String servidor,
                                             java.lang.String database,
                                             java.lang.String login,
                                             java.lang.String senha,
                                             java.lang.String programa)
Obtém uma conexão com um banco de dados SQL Server.

Parameters:
servidor - endereço do servidor
database - nome do banco de dados que deve ser acessado
login - login do usuário que quer acessar o banco
senha - senha do usuário que quer acessar o banco
programa - descrição do programa que está gerenciando a conexão
Returns:
conexão com o banco de dados SQL Server

getUsuario

public static java.lang.String getUsuario(SysConexao sysConexao)

getUsuarioId

public static int getUsuarioId(SysConexao sysConexao)

isMemberOfAdmins

public static boolean isMemberOfAdmins(SysConexao sysConexao)

isMemberOfProcessAdmin

public static boolean isMemberOfProcessAdmin(SysConexao sysConexao)

getNome

public java.lang.String getNome()

setNome

public void setNome(java.lang.String nome)

getDriverType

public SysConexao.DriverType getDriverType()

setDriverType

public void setDriverType(SysConexao.DriverType driverType)

getUrlServidor

public java.lang.String getUrlServidor()

setUrlServidor

public void setUrlServidor(java.lang.String urlServidor)

getNomeDb

public java.lang.String getNomeDb()

setNomeDb

public void setNomeDb(java.lang.String nomeDb)

getNomeAmbiente

public java.lang.String getNomeAmbiente()

setNomeAmbiente

public void setNomeAmbiente(java.lang.String nomeAmbiente)

getLogin

public java.lang.String getLogin()

setLogin

public void setLogin(java.lang.String login)

getSenha

public java.lang.String getSenha()

setSenha

public void setSenha(java.lang.String senha)

getConexao

public java.sql.Connection getConexao()

setConexao

public void setConexao(java.sql.Connection conexao)

getAdminsId

public int getAdminsId()

getUsersId

public int getUsersId()

getSpId

public int getSpId()

getProductVersion

public java.lang.String getProductVersion()

getProductLevel

public java.lang.String getProductLevel()

getEdition

public java.lang.String getEdition()

getUsuario

public java.lang.String getUsuario()

getUsuarioId

public int getUsuarioId()

isDbOwner

public boolean isDbOwner()

isMemberOfAdmins

public boolean isMemberOfAdmins()

isMemberOfProcessAdmin

public boolean isMemberOfProcessAdmin()
Verifica se o usuário que está logado no sistema e membro do grupo processadmin

Returns:
- true indica que o usuário é membro do grupo processadmin

isClosed

public boolean isClosed()
Specified by:
isClosed in interface java.sql.Connection

getAlias

public java.lang.String getAlias()

initGrupos

public void initGrupos(int usuarioID)
Preenche a variável global "Grupos" com a relação de grupos do usuário informado.


initGrupos

public void initGrupos()
Preenche a variável global "Grupos" com a relação de grupos do usuário corrente.


isMemberOf

public boolean isMemberOf(int grupoId)
Informa se o usuário corrente faz parte do grupo informado.

Parameters:
grupoId -
Returns:

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

closeConexao

public void closeConexao()

close

public void close()
           throws java.sql.SQLException
Este método foi alterado para se tornar inativo. O fechamento da conexão deverá ser feito pelo método "closeConexao()".

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency,
                                          int resultSetHoldability)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Specified by:
getAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Specified by:
getCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
Specified by:
getHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Specified by:
getMetaData in interface java.sql.Connection
Throws:
java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Specified by:
getTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

getTypeMap

public java.util.Map<java.lang.String,java.lang.Class<?>> getTypeMap()
                                                              throws java.sql.SQLException
Specified by:
getTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Specified by:
getWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Specified by:
isReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

nativeSQL

public java.lang.String nativeSQL(java.lang.String sql)
                           throws java.sql.SQLException
Specified by:
nativeSQL in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency,
                                              int resultSetHoldability)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int autoGeneratedKeys)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int[] columnIndexes)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   java.lang.String[] columnNames)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency,
                                                   int resultSetHoldability)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
Specified by:
releaseSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback()
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback(java.sql.Savepoint savepoint)
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Specified by:
setAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
Specified by:
setCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

setHoldability

public void setHoldability(int holdability)
                    throws java.sql.SQLException
Specified by:
setHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
Specified by:
setReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String name)
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
Specified by:
setTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

setTypeMap

public void setTypeMap(java.util.Map<java.lang.String,java.lang.Class<?>> map)
                throws java.sql.SQLException
Specified by:
setTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

createArrayOf

public java.sql.Array createArrayOf(java.lang.String typeName,
                                    java.lang.Object[] elements)
                             throws java.sql.SQLException
Specified by:
createArrayOf in interface java.sql.Connection
Throws:
java.sql.SQLException

createBlob

public java.sql.Blob createBlob()
                         throws java.sql.SQLException
Specified by:
createBlob in interface java.sql.Connection
Throws:
java.sql.SQLException

createClob

public java.sql.Clob createClob()
                         throws java.sql.SQLException
Specified by:
createClob in interface java.sql.Connection
Throws:
java.sql.SQLException

createNClob

public java.sql.NClob createNClob()
                           throws java.sql.SQLException
Specified by:
createNClob in interface java.sql.Connection
Throws:
java.sql.SQLException

createSQLXML

public java.sql.SQLXML createSQLXML()
                             throws java.sql.SQLException
Specified by:
createSQLXML in interface java.sql.Connection
Throws:
java.sql.SQLException

createStruct

public java.sql.Struct createStruct(java.lang.String typeName,
                                    java.lang.Object[] attributes)
                             throws java.sql.SQLException
Specified by:
createStruct in interface java.sql.Connection
Throws:
java.sql.SQLException

getClientInfo

public java.util.Properties getClientInfo()
                                   throws java.sql.SQLException
Specified by:
getClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLException

getClientInfo

public java.lang.String getClientInfo(java.lang.String name)
                               throws java.sql.SQLException
Specified by:
getClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLException

isValid

public boolean isValid(int timeout)
                throws java.sql.SQLException
Specified by:
isValid in interface java.sql.Connection
Throws:
java.sql.SQLException

setClientInfo

public void setClientInfo(java.util.Properties properties)
                   throws java.sql.SQLClientInfoException
Specified by:
setClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLClientInfoException

setClientInfo

public void setClientInfo(java.lang.String name,
                          java.lang.String value)
                   throws java.sql.SQLClientInfoException
Specified by:
setClientInfo in interface java.sql.Connection
Throws:
java.sql.SQLClientInfoException

isWrapperFor

public boolean isWrapperFor(java.lang.Class<?> arg0)
                     throws java.sql.SQLException
Specified by:
isWrapperFor in interface java.sql.Wrapper
Throws:
java.sql.SQLException

unwrap

public <T> T unwrap(java.lang.Class<T> arg0)
         throws java.sql.SQLException
Specified by:
unwrap in interface java.sql.Wrapper
Throws:
java.sql.SQLException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getListaConexoes

public static java.util.ArrayList<java.lang.String> getListaConexoes()

saveConexao

public void saveConexao()
Salva a conexão em arquivo


saveConexao

public static void saveConexao(SysConexao sysConexao)
Salva a conexão em arquivo

Parameters:
sysConexao -

readConexao

public void readConexao()
Carrega a conexão de um arquivo no formato cnx

Parameters:
nomeConexao -

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getUsuarioUS

public static java.lang.String getUsuarioUS(int id)
Retorna o nome técnico do usuário no banco de dados no formato US_XXXXX.

Parameters:
id -
Returns:

getGrupoGR

public static java.lang.String getGrupoGR(int id)
Retorna o nome técnico do grupo no banco de dados no formato GR_XXXXX.

Parameters:
id -
Returns: